#include "nvs.h"
#include "dev_flash.h"

#include <stdio.h>
#include <string.h>


#define ADDRESS_ID 0x01


int main()
{
    int rc;
    static struct nvs_fs fs;
    const struct flash_device_t * dev = flash_device_get_api();
    struct flash_pages_info info;
    char buf[100];
    
    printf("NVS Example \r\n");

    fs.offset = 0;
    fs.flash_device = dev;

    flash_get_page_info_by_offs(dev ,fs.offset , &info );

    fs.sector_size = 0x1000;
    fs.sector_count = 2U;

    rc = nvs_mount(&fs);

    strcpy(buf , "msg call test");
      
    (void)nvs_write(&fs, ADDRESS_ID, &buf, strlen(buf)+1);
    if (rc < 0){
        printf("write failed!\n");
    }

    rc = nvs_read(&fs, ADDRESS_ID, &buf, sizeof(buf));
    if (rc > 0) { /* item was found, show it */
        printf("Id: %d, Address: %s\n", ADDRESS_ID, buf);
    }
    else {
        printf("read failed!\n");
    }


}